package com.woniuxy.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.woniuxy.entity.LoanUserInfo;
import com.woniuxy.service.ILoanUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @description: TODO 用户信息控制层
 * @author jx
 * @date 2022/9/19 14:24
 * @version 1.0
// */
@RestController
@RequestMapping("/userinfo")
public class LoanUserInfoController extends BaseController {


    private ILoanUserInfoService loanUserInfoService;

    /**
     *查询用户信息
     * @param loanUserInfo
     * @return
     */

//    @PreAuthorize("@ss.hasPermi('loan:userinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(LoanUserInfo loanUserInfo){
        startPage();
        List<LoanUserInfo> list = loanUserInfoService.selectLoanUserInfoList(loanUserInfo);
        return getDataTable(list);
    }


    /**
     * 添加用户信息 补全信息
     * @param loanUserInfo
     * @return
     */
    //权限
//    @PreAuthorize("@ss.hasPermi('loan:userinfo:add')")
    @Log(title = "用户信息",businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LoanUserInfo loanUserInfo){
        //获得当前登录的用户名，保存到对应实体类 创建者，时间
        loanUserInfo.setCreateBy(getUsername());
        return toAjax(loanUserInfoService.insertUserInfo(loanUserInfo));


    }

    //删除
//    @PreAuthorize("@ss.hasPermi('loan:userinfo:add')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userinfoid}")
    public AjaxResult delete(@PathVariable int id)
    {
        return toAjax(loanUserInfoService.deleteUserInfoById(id));
    }


    //修改
//    @PreAuthorize("@ss.hasPermi('loan:userinfo:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody LoanUserInfo loanUserInfo)
    {

        loanUserInfo.setUpdateBy(getUsername());
        return toAjax(loanUserInfoService.updateLoanUserInfo(loanUserInfo));
    }


}
